#include "sleeworddoc.h"
#include <QDebug>

SleeWordDoc::SleeWordDoc(const SleeQAxPtr &_doc, quint32 id):
    m_doc(_doc),
    m_id(id)
{
}


void SleeWordDoc::close(bool do_save)
{
    if(!do_save)
        m_doc.mp->dynamicCall("Close(const QVariant &)", QVariant(0));
    else
        m_doc.mp->dynamicCall("Close(const QVariant &)", QVariant(1));
    m_doc.free_ptr();
}


void SleeWordDoc::save()
{
    m_doc.mp->dynamicCall("Save()");
}

void SleeWordDoc::save_as(const QString &file_pathname)
{
    m_doc.mp->dynamicCall("SaveAs(QVariant)", QVariant(file_pathname));
}

bool SleeWordDoc::replace(const QString & qstr_target, const QString & qstr_new)
{
    qDebug()<<Q_FUNC_INFO<<" ... "<<qstr_target<<" << "<< qstr_new;
    QAxObject *p_range = m_doc.mp->querySubObject("Range()");
    QAxObject *p_find = p_range->querySubObject("Find()");

    ////(QVariant& FindText = 0,
    //// QVariant& MatchCase = 0,
    //// QVariant& MatchWholeWord = 0,
    //// QVariant& MatchWildcards = 0,
    //// QVariant& MatchSoundsLike = 0,
    //// QVariant& MatchAllWordForms = 0,
    //// QVariant& Forward = 0,
    //// QVariant& Wrap = 0,
    //// QVariant& Format = 0,

    qDebug()<<Q_FUNC_INFO<<" ... ranges set .. OK";
    QList<QVariant> qv_arg_list;
    qv_arg_list<< QVariant(qstr_target)<<QVariant()<<QVariant()<<QVariant()<<QVariant()<<QVariant()<<QVariant(true)<<QVariant()<<QVariant()<<QVariant(qstr_new);
    bool b_res;
    b_res = p_find->dynamicCall("Execute(QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant, QVariant)",
                            qv_arg_list).toBool();

    qDebug()<<Q_FUNC_INFO<<" ... find execution .. OK";
    delete p_find;
    delete p_range;
    qDebug()<<Q_FUNC_INFO<<" ok";
    return b_res;
}
